package TCPBasics;

import java.io.*;
import java.net.*;

public class TCPClient
{		
 public static void main(String argv[]) throws Exception
 {
  String sentence;
  String modifiedSentence;
  int port = 5789;
  int comm_port_num = 0;
  int x_coordinate = -1, y_coordinate = -1; 
  
  System.out.println(argv.length);
  for (String s : argv){
	  System.out.println("Input " + s);
  }
  
  try{
	  comm_port_num = Integer.parseInt(argv[0]);
  } catch (Exception e){
	  System.out.println("Invalid port number.");
	  System.exit(1);
  }
  
  BufferedReader inFromUser = new BufferedReader( new InputStreamReader(System.in));
  Socket clientSocket = new Socket("localhost", port);
  DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
  BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
  
  sentence = Integer.toString(comm_port_num);
	  
  outToServer.writeBytes(sentence + '\n');  
  try{
	  modifiedSentence = inFromServer.readLine();
	  System.out.println("FROM SERVER: " + modifiedSentence);
  }
  catch (Exception e){
	  //e.printStackTrace();
  }
  clientSocket.close();
 }
}
